package com.tengju.support.domain.model.article;

import com.tengju.support.domain.shared.DomainException;
import com.tengju.support.domain.shared.DomainExceptionCode;
import java.time.LocalDateTime;
import org.springframework.util.StringUtils;

public class ArticleFactory {

    public static Article create(String title, ArticleType type, String context, String createBy) {

        if (StringUtils.isEmpty(title)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA, "标题为空");
        }
        if (type == null) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA, "文章类型为空");
        }
        if (StringUtils.isEmpty(context)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA, "文章内容为空");
        }
        if (StringUtils.isEmpty(createBy)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA, "操作人为空");
        }
        return new Article(
                null, title,
                type, context,
                createBy, createBy, LocalDateTime.now(),null);
    }

}
